package com.frame.pageform.tag;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.lang.StringUtils;


public class DateTag extends BaseTag{

	private String bind;
	private String format;


	public int start() throws Exception
	{

		try {
			Object value = executeExpression(bind.replaceAll("'", "\""));
			String s="";
			if(value!=null && !"".equals(value)){
				if(StringUtils.isBlank(format))format="yyyy-MM-dd";
				SimpleDateFormat sp=new SimpleDateFormat(format);
				Date date=new Date(Long.parseLong(value.toString()));
				s=sp.format(date);
			}
			write(s);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}catch(Exception e){
			e.printStackTrace();
		}
		return 0;
	}

	public String getBind() {
		return bind;
	}

	public void setBind(String bind) {
		this.bind = bind;
	}

	public String getFormat() {
		return format;
	}

	public void setFormat(String format) {
		this.format = format;
	}
}
